﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using MVCManage.BLL;
using MVCManage.Model;
using MVCManage.Api.Models;
using System.Xml.XPath;
namespace MVCManage.Api.Controllers
{
    public class ImagesController : ApiController
    {
        // GET: api/Images
       
        ImagesBLL bll = new ImagesBLL();
        // GET: api/Images/5
        public ResultData<List<ImageDto>> Get()
        {

            var data = from n in bll.Dal.Query()
                       select new ImageDto()
                       {
                           ImgID = n.imgID,
                           LastTime = n.lastTime,
                           Extension = n.extension,
                           Modular = n.modular,
                           Path = n.path,
                           Size = n.size,
                           title = n.title,
                       };
            ResultData<List<ImageDto>> result = new ResultData<List<ImageDto>>();
            result.code = 1;
            result.data = data.ToList();
            return result;
           
        }

        public Result Put([FromBody] UserDto value)
        {
            var users = new YhBLL().Query().Where(n => n.userID == value.UserID).FirstOrDefault();
            Result result = new Result();
            if (users != null)
            {
                users.imgID = value.ImgID;
                var zz = new YhBLL().Update(users);

                result.code = zz ? 1 : 0;
                result.msg = zz ? "修改成功" : "修改失败";
            }
            else
            {
                result.code = -1;
                result.msg = "未找到数据!";
            }
            return result;
        }






    }
}
